(function(app){
	app
		.controller("history_detailCtrl",["$scope","myFactory",'$http','$state','$stateParams','$ionicHistory',function($scope,myFactory,$http,$state,$stateParams,$ionicHistory){
			//接收参数
			var mid=$stateParams.mid;
			var itemids=$stateParams.itemids;
			var searchParam = $stateParams.searchParam;
			var itemData;//用于接收后台返回回来的查询的变更记录
			var charge="";//收付费账户信息
			var initFlag = false;//检测标志，在初始化函数完成后，会被置为true
//			console.log(mid);
//			console.log(itemids);
			var token=sessionStorage.getItem("token");
			
			//绑定参数
			$scope.showAccountFlag = false;//是否显示收付费账户信息，默认不显示
			
/**********************************************初始化函数begin****************************************************/		
			//初始化查询变更项内容
			$scope.load = function () {
				myFactory.loadingShow();//显示加载圈
				var timestamp=myFactory.getTimetamp();
				var sfis= "mid-itemid-token-timestamp";
				var signStr="mid="+mid+"&itemid="+itemids+"&token="+token+"&timestamp="+timestamp;//encodeURI(name)
				var sign = myFactory.hex(signStr);
				$http({
					method: 'GET',
					url: app.domain + 'history/queryRestModifyInfo.action',
					params: {'mid': mid,'itemid': itemids,'sign':sign,'sfis':sfis,'token':token,'timestamp':timestamp}
				}).then(function successCallback(response) {
					if (response.data.success) {
						itemData = response.data.data;
						charge = itemData.charge;
						$scope.polplndsc=itemData.polplndsc;//主险名称
						$scope.cownname=itemData.cownname;//被保人姓名
						$scope.apstate=itemData.itemBase[0].apstate;//处理状态
						$scope.chdrnum=itemData.chdrnum;//保单号
						$scope.itemBase = itemData.itemBase;
						$scope.itemDetail = response.data.data;
						
						//更改项目显示名字
						for(var i=0 ; i<$scope.itemBase.length;i++){
							if("12_42" == $scope.itemBase[i].itemid){
								$scope.itemBase[i].itemName = "补发尊贵客户卡";
							}
						}
						
						//收付费账户信息部分初始化
						if(charge != null &&  charge != undefined && charge != ""){
							$scope.showAccountFlag = true;//显示收付费账户信息
							
							//填充数据
							var accountFlag = charge.accountFlag;
							if(accountFlag=="1"){//如果是选择的是续期账户
								$scope.typeName = "续期账户";  //类型
								$scope.paynme = charge.paynme1.trim(); //名字
								$scope.bankdesc = charge.bankdesc1.trim(); //银行
								$scope.citydesc = charge.citydesc1.trim();//开户城市
								$scope.bankacctkey = charge.bankacctkey1.trim();//账号
							}else if(accountFlag=="3"){//如果选择的是首期缴费账户
								$scope.typeName = "首期缴费账户";
								$scope.paynme = charge.paynme3.trim();
								$scope.bankdesc = charge.bankdesc3.trim();
								$scope.citydesc = charge.citydesc3.trim();
								$scope.bankacctkey = charge.bankacctkey3.trim();//账号
							}else if(accountFlag=="2"){//如果选择的是其他账户
								$scope.typeName = "其他账户";
								$scope.paynme = charge.paynme.trim();
								$scope.bankdesc = charge.bankdesc.trim();
								$scope.citydesc = charge.citydesc.trim();
								$scope.bankacctkey = charge.bankacctkey.trim();//账号
							}
						}
						initFlag = true;
					}
					myFactory.loadingHide();
				}, function errorCallback(response) {
					myFactory.loadingHide();
					myFactory.alert("","初始化查询变更项内容失败!","info");
				});
			}
/**********************************************初始化函数end****************************************************/	

			$scope.goBack = function () {
				//返回查询页面,返回查询条件
				//myFactory.goBack();
				$state.go('search',{
					searchParam:searchParam
				});
			}
			
			$scope.toChangeDetail = function(id){
				if("01"==id){
					//封装所需数据
					var item01Temp = itemData.item01;
					$ionicHistory.clearCache().then(function(){ 
						$state.go('content_01_check',{
							"item01":item01Temp,
							"chdrnum01":$scope.chdrnum,
							"mid":mid,
							"itemids":itemids,
							"state":"history_detail"
						});
					});
				}
				if("02_1"==id){
					var item = itemData.item02_1;
					$ionicHistory.clearCache().then(function(){ 
						$state.go('content_02_1_check',{
							"chdrnum01":$scope.chdrnum,
							"item02_1":item,
							"state":"history_detail"
						});
					});
				}
				if("02_2"==id){
					var item = itemData.item02_2;
					$ionicHistory.clearCache().then(function(){ 
						$state.go('content_02_2_check',{
							"chdrnum01":$scope.chdrnum,
							"item02_2":item,
							"state":"history_detail"
						});
					});
				}
				if("03"==id){
					var item = itemData.item03;
					$ionicHistory.clearCache().then(function(){ 
						$state.go('content_03_check',{
							"chdrnum01":$scope.chdrnum,
							"item03":item,
							"state":"history_detail"
						});
					});
				}
				if("05"==id){
					var item = itemData.item05;
					$ionicHistory.clearCache().then(function(){ 
						$state.go('content_05_check',{
							"chdrnum01":$scope.chdrnum,
							"item05":item,
							"state":"history_detail"
						});
					});
				}
				if("08"==id){
					var item = itemData.item08;
					$ionicHistory.clearCache().then(function(){ 
						$state.go('content_08_check',{
							"chdrnum01":$scope.chdrnum,
							"item08":item,
							"state":"history_detail"
						});
					});
				}
				if("10"==id){
					var item10 = itemData.item10;
					$ionicHistory.clearCache().then(function(){
						$state.go('content_10_check',{
							"chdrnum01":$scope.chdrnum,
							//"chdrcoy":chdrcoy,
							"state":"history_detail",
							"item10":item10
						});
					});
				}
				if("12_42"==id || "12"==id || "42"==id){//补发尊贵客户卡
					var item42=itemData.item42;
					var item12=itemData.item12;
					$ionicHistory.clearCache().then(function(){
						$state.go('content_12_42_check',{
							"chdrnum01" : $scope.chdrnum,
							//"chdrcoy" : chdrcoy,
							"item42" : item42,
							"item12" : item12
						});
					});
				}
				if("19"==id){
					var item19 = itemData.item19;
					$ionicHistory.clearCache().then(function(){
						$state.go('content_19_check',{
							"chdrnum01":$scope.chdrnum,
							//"chdrcoy":chdrcoy,
							"state":"history_detail",
							"item19":item19
						});
					});
				}
				if("27"==id){
					var item27 = itemData.item27;
					$ionicHistory.clearCache().then(function(){
						$state.go('content_27_check',{
							"chdrnum01":$scope.chdrnum,
							//"chdrcoy":chdrcoy,
							"state":"history_detail",
							"item27":item27
						});
					});
				}
				if("28"==id){
					var item28 = itemData.item28;
					$ionicHistory.clearCache().then(function(){
						$state.go('content_28_check',{
							"chdrnum01":$scope.chdrnum,
							//"chdrcoy":chdrcoy,
							"state":"history_detail",
							"item28":item27
						});
					});
				}
				if("35"==id){
					$ionicHistory.clearCache().then(function(){ 
						$state.go('content_35_check',{
							"chdrnum01":$scope.chdrnum,
							"state":"history_detail"
						});
					});
				}
				if("36"==id){
					$ionicHistory.clearCache().then(function(){ 
						$state.go('content_36_check',{
							"chdrnum01":$scope.chdrnum,
							"state":"history_detail"
						});
					});
				}
				if("45"==id){
					var item45 = itemData.item45;
					$ionicHistory.clearCache().then(function(){ 
						$state.go('content_45_check',{
							"chdrnum01":$scope.chdrnum,
							"state":"history_detail",
							"item45":item45
						});
					});
				}
				//S2018122906735移动保全新增变更项目及功能的优化需求 add by mqz 20191225 start
				if("15"==id){//保险计划
					$ionicHistory.clearCache().then(function(){ 
						$state.go('content_15_check',{
							"chdrnum01":$scope.chdrnum,
							"state":"history_detail"
						});
					});
				}
				if("29"==id){//取消承保条件
					$ionicHistory.clearCache().then(function(){ 
						$state.go('content_29_check',{
							"chdrnum01":$scope.chdrnum,
							"state":"history_detail"
						});
					});
				}
				if("30"==id){//补充告知
					$ionicHistory.clearCache().then(function(){ 
						$state.go('content_30_check',{
							"chdrnum01":$scope.chdrnum,
							"state":"history_detail"
						});
					});
				}
				//S2018122906735移动保全新增变更项目及功能的优化需求 add by mqz 20191225 end
			}

		}])
})(app)